<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>找回密码</title>
    <script src="__JS__/jquery.js"></script>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
<div style="height: 100px;"></div>
<div style="width: 500px;height:400px;margin: 0 auto;border: 1px solid #dddddd;" >
    <div >
        <div style="width: 200px;float: left;font-size: 25px">
            发送重置密码邮件
        </div>
        <div style="width:70px;float: right">
            <button type="button" id="login" class="btn btn-link">返回登录</button>
        </div>
    </div>
    <div style="height: 80px;"></div>
    <div style="width: 400px;margin-left: 40px;">
        <label style="display: none;color: red;text-align: center" id="info"></label>
        <form class="layui-form" action="" id="myform">
            <div class="layui-form-item">
                <label class="layui-form-label">邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</label>
                <div class="layui-input-block">
                    <input type="text" style="width: 300px" onblur="verification()" name="email" required  lay-verify="required" placeholder="邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码:</label>
                <div class="layui-input-block" >
                    <div style="width: 150px;float: left">
                        <input type="text" style="width:100px"  name="code" required  lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input">
                    </div>
                    <div style="width: 100px;float: right">
                        <img src="{:url('business/forget/code')}" onclick="this.src='{:url(\'business/forget/code\')}?id='+Math.random()" width="80" height="38">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" id="send" class="btn btn-primary" style="width: 200px">发送</button>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<script>
    //返回登录
    $("#login").click(function () {
        window.location.href = "{:url('business/login/index')}"
    });
    //邮箱验证
    function verification() {
        var email = $("input[name=email]").val();
        var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
        if(!email){
            $("#info").html('请输入邮箱');
            $("#info").css('display','block');
            return ;
        }
        if(!reg.test(email)){
            $("#info").html('邮箱格式不正确');
            $("#info").css('display','block');
            return ;
        }
        $("#info").css('display','none');
    }
    //发送验证
    $("#send").click(function () {
        var email = $("input[name=email]").val();
        if(!email){
            $("#info").html('请输入邮箱');
            $("#info").css('display','block');
            return;
        }
        var code = $("input[name=email]").val();
        if(!code){
            $("#info").html('请输入验证码');
            $("#info").css('display','block');
            return;
        }
        $.ajax({
            url:"{:url('business/forget/sendemail')}",
            data:$("#myform").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success);
                }
                if(res.error){
                    $("#info").html(res.error);
                    $("#info").css('display','block');
                    return;
                }
            }
        });
    });
</script>
</html>